package com.atguigu.springbootdemo.service;

import com.atguigu.springbootdemo.bean.Employee;
import com.atguigu.springbootdemo.bean.Region;
import com.atguigu.springbootdemo.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/*
@Service:
    1、给你和你的同事看，表明这个类是一个业务模型
    2、容器扫描到这个类，发现头顶上顶了@Service，就会在容器中创建这个类型的单例对象
 */
@Service
public class EmployeeServiceImpl implements EmployeeService{
    //引入dao读取数据库
    @Autowired
    private EmployeeMapper mapper;
    @Override
    public Employee getEmployeeById(Integer id) {
        System.out.println("需要先这样...");
        Employee employee = mapper.getEmployeeById(id);
        System.out.println("之后再那样...");
        return employee;
    }

    @Override
    public void insertEmployee(Employee employee) {
        System.out.println("需要先这样...");
        mapper.insertEmployee(employee);
        System.out.println("之后再那样...");
    }

    @Override
    public void updateEmployee(Employee employee) {
        System.out.println("需要先这样...");
        mapper.updateEmployee(employee);
        System.out.println("之后再那样...");
    }

    @Override
    public void deleteEmployeeById(Integer id) {
        System.out.println("需要先这样...");
        mapper.deleteEmployeeById(id);
        System.out.println("之后再那样...");
    }

    @Override
    public List<Employee> getAll() {
        System.out.println("需要先这样...");
        List<Employee> all = (List<Employee>) mapper.getAll();
        System.out.println("之后再那样...");
        return all;
    }

    @Override
    public String sayHello() {
        return "hello";
    }

    @Override
    public List<Region> getAllRegion() {
        return mapper.getAllRegion();
    }
}

//public class EmployeeServiceImpl implements EmployeeService{
//
//    //引入dao读取数据库
//    private EmployeeService mapper;
//    @Override
//    public Employee getEmployeeById(Integer id) {
//        System.out.println("需要先这样....");
//        Employee employee = mapper.getEmployeeById(id);
//        System.out.println("之后再那样.....");
//        return employee;
//    }
//
//    @Override
//    public void insertEmployee(Employee employee) {
//        System.out.println("需要先这样....");
//        mapper.insertEmployee(employee);
//        System.out.println("之后再那样.....");
//    }
//
//    @Override
//    public void updateEmployee(Employee employee) {
//        System.out.println("需要先这样....");
//        mapper.updateEmployee(employee);
//        System.out.println("之后再那样.....");
//    }
//
//    @Override
//    public void deleteEmployeeById(Integer id) {
//        System.out.println("需要先这样....");
//        mapper.deleteEmployeeById(id);
//        System.out.println("之后再那样.....");
//    }
//
//    @Override
//    public List<Employee> getAll() {
//        System.out.println("需要先这样....");
//        List<Employee> all = mapper.getAll();
//        System.out.println("之后再那样.....");
//        return all;
//    }
//}